package com.e5.training.action;

import org.apache.struts2.json.annotations.JSON;
import org.springframework.beans.factory.annotation.Autowired;

import com.e5.training.domain.User;
import com.e5.training.service.UserService;

public class UserValiadAction {
	@Autowired
	private UserService userService;

	private String userid;
	private boolean isValid;

	@JSON(serialize = false)
	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	/**
	 * @return the isDel
	 */
	@JSON(name = "isExist")
	public boolean getIsValid() {
		return isValid;
	}

	/**
	 * @param isDel
	 *            the isDel to set
	 */
	public void setIsValid(boolean isDel) {
		this.isValid = isDel;
	}

	public String execute() {
		boolean isd = false;
		try {
			// delete user
			User u = userService.getUserByUserId(userid);

			if(u!=null&&u.getUserID().equals(getUserid())){
				isd =true;
			}else{
				isd = false;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		this.setIsValid(isd);
		return "success";
	}
}
